<template>
  <div>
    <!--    分类页面-->
    <div style="text-align: right">

      <el-radio-group v-model="queryForm.status" type="info" size="medium" @change="getList" fill="#209e91">

        <el-radio-button label="制单"></el-radio-button>
        <el-radio-button label="已拒绝"></el-radio-button>
        <el-radio-button label="待领取"></el-radio-button>
        <el-radio-button label="待提货"></el-radio-button>
        <el-radio-button label="提货中"></el-radio-button>
        <el-radio-button label="待发车"></el-radio-button>
        <el-radio-button label="运输中"></el-radio-button>
        <el-radio-button label="已完成"></el-radio-button>
        <el-radio-button label="已取消"></el-radio-button>
        <el-radio-button label="">全部</el-radio-button>
      </el-radio-group>
    </div>
    <el-row>
      <el-col :span="24"><div class="grid-content bg-purple-light">
        <div style="float: left; margin: 20px 100px; font-weight: 700;color:#606266;font-size: 20px"><i class="el-icon-search"></i>调度单查询</div>
      </div></el-col>
    </el-row>
    <!--  查询条件-->
    <el-form :inline="true" :model="queryForm" style="text-align: left; margin: 0 10%">
      <el-form-item label="调度单号:">
        <el-input v-model="queryForm.ticketId" placeholder="调度单号" clearable></el-input>
      </el-form-item>
      <el-form-item label="车牌号:">
        <el-input v-model="queryForm.carNumber" placeholder="车牌号" clearable></el-input>
      </el-form-item>
      <el-form-item label="司机姓名:">
        <el-input v-model="queryForm.carInfo.anotherOne" placeholder="司机姓名" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="info" @click="getList" plain>查询</el-button>
        <el-button type="info" @click="add()" plain>新增</el-button>
      </el-form-item>
    </el-form>
    <el-row>
      <el-col :span="24"><div class="grid-content bg-purple-light">
        <div style="float: left; margin: 0 100px; font-weight: 700;color:#606266;font-size: 20px"><i class="el-icon-s-unfold"></i>数据列表</div>
      </div></el-col>
    </el-row>
    <!--  数据表格-->
    <div id="s" class="animate__animated animate__zoomIn animate__delay-0.5s" style="margin-top: 20px">
      <el-table :data="tableData" stripe style="width: 100%;" :border="true"
                :header-cell-style="{background:'#209e91', color:'#ffffff',textAlign:'center'}"
                :default-sort="{prop: 'createTime', order: 'descending'}">
        <el-table-column
          label="序号"
          width="50"
          type="index"
          :index="No"
          align="center"
          fixed>
        </el-table-column>
        <el-table-column
          prop="ticketId"
          label="调度单号"
          align="center"
          width="180">
        </el-table-column>
        <el-table-column
          prop="status"
          label="状态"
          align="center"
          width="120">
        </el-table-column>
        <el-table-column
          prop="type"
          label="类型"
          align="center"
          width="120">
        </el-table-column>
        <el-table-column
          prop="carNumber"
          label="车牌号"
          align="center"
          width="180">
        </el-table-column>
        <el-table-column
          prop="startTime"
          sortable
          label="预计发货时间"
          align="center"
          width="150">
        </el-table-column>
        <el-table-column
          prop="endTime"
          sortable
          label="预计到货时间"
          align="center"
          width="150">
        </el-table-column>
        <el-table-column
          prop="carInfo.type"
          label="车类型"
          align="center"
          width="120">
        </el-table-column>
        <el-table-column
          prop="carInfo.anotherOne"
          label="司机"
          align="center"
          width="150">
        </el-table-column>
        <el-table-column
          prop="startAreaName"
          label="起点"
          align="center"
          width="180">
        </el-table-column>
        <el-table-column
          prop="endAreaName"
          label="终点"
          align="center"
          width="180">
        </el-table-column>
        <el-table-column
          prop="createId"
          label="创建人员"
          align="center"
          width="100">
        </el-table-column>
        <el-table-column
          prop="createTime"
          sortable
          label="创建时间"
          align="center"
          width="150">
        </el-table-column>
        <el-table-column
          label="操作"
          width="150"
          align="center"
          fixed="right">
          <template v-slot="scope">
            <el-button v-if="buttonGroup.indexOf(scope.row.status) !=-1 ? true : false" @click="edit(scope.row)"
                       type="text" size="small">编辑
            </el-button>
            <el-popconfirm title="确定提交吗？" @confirm="submit(scope.row)">
              <el-button v-if="buttonGroup.indexOf(scope.row.status) !=-1 ? true : false" slot="reference" type="text"
                         size="small">提交
              </el-button>
            </el-popconfirm>
            <el-popconfirm title="确定删除吗？" @confirm="remove(scope.row)">
              <el-button v-if="buttonGroup.indexOf(scope.row.status) !=-1 ? true : false" slot="reference" type="text"
                         size="small">删除
              </el-button>
            </el-popconfirm>
            <el-popconfirm title="确定撤销吗？" @confirm="quash(scope.row)">
              <el-button v-if="scope.row.status =='待领取' ? true : false" slot="reference" type="text" size="small">撤销
              </el-button>
            </el-popconfirm>
            <el-button v-if="buttonGroup.indexOf(scope.row.status) ==-1 ? true : false" @click="check(scope.row)"
                       type="text" size="small">查看
            </el-button>
          </template>
        </el-table-column>
      </el-table>

    <el-row>
      <el-col :span="24"><div class="grid-content bg-purple-light">
        <div style="margin: 20px"></div>
      </div></el-col>
    </el-row>
    <!--  分页-->
    <el-pagination
      @size-change="getList"
      @current-change="getList"
      :current-page.sync="queryForm.pageNum"
      :page-sizes="[10, 20, 30, 40, 60, 80, 100]"
      :page-size.sync="queryForm.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
    <el-row>
      <el-col :span="24"><div class="grid-content bg-purple-light">
        <div style="margin: 20px"></div>
      </div></el-col>
    </el-row>
    </div>
  </div>
</template>
<script>

export default {
  name: "DispatchTicket",
  data() {
    return {
      //查询对象
      queryForm: {
        status: '制单',
        ticketId: '',
        carNumber: '',
        carInfo: {},
        pageNum: 1,
        pageSize: 10
      },
      //表格数组
      tableData: [],
      //共多少条
      total: 0,
      //显示修改删除按钮
      show: false,
      //按钮分组
      buttonGroup: ['制单', '已拒绝', '已取消']
    }
  },
  methods: {
    No(index) {
      // 当前页数 - 1 * 每页数据条数 + 1
      const page = this.queryForm.pageNum // 当前页码
      const pagesize = this.queryForm.pageSize // 每页条数
      return (page - 1) * pagesize + index + 1
    },
    getList() {
      this.$axios({
        url: 'dispatch/ticket/list',
        method: 'post',
        data: this.queryForm
      }).then(res => {
        if (res.data.success) {
          this.tableData = res.data.object.list;
          this.total = res.data.object.total;
        }
      }).catch(err => {
        this.$message.error(err.message);
      })
    },
    success() {
      this.getList()
    },
    add() {
      this.$router.push('DispatchAdd')
    },
    edit(row) {
      this.$store.commit('dispatchOption', 'edit')
      this.$store.commit('currentDispatchTicket', row)
      this.$router.push('DispatchEdit')
    },
    submit(row) {
      row.status = '待领取';
      this.$axios({
        url: 'dispatch/ticket/update',
        method: 'post',
        data: row
      }).then(res => {
        if (res.data.success) {
          this.$message({
            showClose: true,
            message: '提交成功',
            type: 'success'
          });
        } else {
          this.$message(res.data.message);
        }
        this.getList()
      }).catch(err => {
        this.$message.error(err.message);
      })
    },
    check(row) {
      this.$store.commit('currentDispatchTicket', row)
      this.$router.push('DispatchDetail')
    },
    quash(row) {
      row.status = '已取消';
      this.$axios({
        url: 'dispatch/ticket/update',
        method: 'post',
        data: row
      }).then(res => {
        if (res.data.success) {
          this.getList()
        }
      }).catch(err => {
        this.$message.error(err.message);
      })
    },

    remove(row) {
      this.$axios({
        url: 'dispatch/ticket/remove/',
        method: 'post',
        data: row
      }).then(res => {
        if (res.data.success) {
          this.$message({
            message: res.data.message,
            type: 'success'
          });
          this.getList();
        } else {
          this.$message.error(res.data.message);
        }
      }).catch(err => {
        this.$message.error(err.message);
      })
    }

  },
  created() {
    this.getList()
  },
  computed: {}
}
</script>

<style scoped>
.el-select {
  width: 100%;
}
#s{
  width:90%;
  margin:10px auto;
  background-color: #ffffff;
  box-shadow: 10px 10px 5px #c4c6c7;
  border-radius: 5px
}
.el-button--info:hover {
  background: #209e91;
  border-color: #209e91;
  color: #FFF;
}


 .set-other-btn{
  color: #fff;
  background-color: #FA4EAB;
  border-color: #FA4EAB;
     }
.set-other-btn:hover {
background-color: #FE83C6;
  border-color: #FE83C6;
}

.set-other-btn:focus {
background-color:  #FE83C6;
  border-color:  #FE83C6;
}




</style>
